import os


def get_dirs_fullpath(dir_path):
    dirs = list(filter(lambda x: os.path.isdir(x), os.listdir(dir_path)))
    all_fullpath = list(map(lambda x: os.getcwd().replace('\\', '/') + '/' + x, dirs))
    return all_fullpath


def check_git_win(path):
    dirs = get_dirs_fullpath(path)
    for d in dirs:
        cmd = 'cd /' + d[0] + ' ' + d + ' & git status'
        ret_msg = os.popen(cmd).readlines()
        print(cmd)
        for line in ret_msg:
            print(line, end='') # 不带换行的print
        print('\n')


def check_git_linux(path):
    dirs = get_dirs_fullpath(path)
    for d in dirs:
        cmd = 'cd ' + d + ';git status'
        ret_msg = os.popen(cmd).readlines()
        print(cmd) # 不带换行的print
        for line in ret_msg:
            print(line, end='')
        print('\n')


def check_git(path):
    import sys
    if sys.platform == 'win32':
        check_git_win(path)
    else:
        check_git_linux(path)


if __name__ == '__main__':
    check_git('.')
